package cn.edu.zafu.bigdata.linfeifei.I;

import java.io.*;
import java.net.*;

public class TcpClient {
    public static void main(String[] args) {
        String hostname = "127.0.0.1"; // 服务端IP地址
        int port = 1234; // 服务端端口号

        try (Socket socket = new Socket(hostname, port);
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
             BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))) {

            System.out.println("Connected to server");

            String userInput;
            while ((userInput = stdIn.readLine()) != null) {
                out.println(userInput);
                System.out.println("Server response: " + in.readLine());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
